//
//  ReadViewController.m
//  WangYiNews
//
//  Created by lanou3g on 15/10/10.
//  Copyright (c) 2015年 zhengming. All rights reserved.
//

#import "ReadViewController.h"

@interface ReadViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIView *barView; // 容器
@property (nonatomic, strong) UILabel *lineLabel; // 下划白线
@property (nonatomic, strong) UIButton *commendReadBtn; // 我的订阅
@property (nonatomic, strong) UIButton *myReadBtn; // 推荐阅读

@property (nonatomic, strong) UIBarButtonItem *addBtn; // 订阅

@end

@implementation ReadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self subView];
}

- (void)subView
{
    self.ReadBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 50)];
    self.ReadBar.barTintColor = [UIColor redColor];
    [self.view addSubview:self.ReadBar];
    
    self.barView = [[UIView alloc] initWithFrame:CGRectMake(15, 20, 140, 30)];
    self.barView.backgroundColor = [UIColor clearColor];
    [self.ReadBar addSubview:self.barView];
    
    self.commendReadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.commendReadBtn.frame = CGRectMake(0, 0, 70, 30);
    self.commendReadBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.commendReadBtn setTitle:@"推荐订阅" forState:UIControlStateNormal];
    [self.commendReadBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    self.commendReadBtn.alpha =  1;
    [self.commendReadBtn addTarget:self action:@selector(commendReadBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.barView addSubview:self.commendReadBtn];
    
    self.myReadBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.myReadBtn.frame = CGRectMake(70, 0, 70, 30);
    [self.myReadBtn setTitle:@"我的订阅" forState:UIControlStateNormal];
    [self.myReadBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.myReadBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    self.myReadBtn.alpha = 0.6;
    [self.myReadBtn addTarget:self action:@selector(myReadBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.barView addSubview:self.myReadBtn];
    
    self.lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 28, 70, 2)];
    self.lineLabel.backgroundColor = [UIColor whiteColor];
    [self.barView addSubview:self.lineLabel];
    
    self.scrollView.delegate = self;
}

#pragma mark -按钮点击事件
- (void)commendReadBtnAction:(UIButton *)commentReadBtn
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect frame = self.lineLabel.frame;
        frame.origin.x = 0;
        self.lineLabel.frame = frame;
        self.commendReadBtn.alpha = 1;
        self.myReadBtn.alpha = 0.6;
        CGPoint point = self.scrollView.contentOffset;
        point.x = 0;
        self.scrollView.contentOffset = point;
    }];
}

- (void)myReadBtnAction:(UIButton *)myReadBtn
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect frame = self.lineLabel.frame;
        frame.origin.x = self.barView.frame.size.width / 2;
        self.lineLabel.frame = frame;
        self.commendReadBtn.alpha = 0.6;
        self.myReadBtn.alpha = 1;
        
        CGPoint point = self.scrollView.contentOffset;
        point.x = kScreenWidth;
        self.scrollView.contentOffset = point;
    }];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat scale = scrollView.contentOffset.x / kScreenWidth;
    CGRect frame = self.lineLabel.frame;
    frame.origin.x = self.barView.frame.size.width / 2 * scale;
    self.lineLabel.frame = frame;
    self.commendReadBtn.alpha = 1 - 0.4 * scale;
    self.myReadBtn.alpha = 0.6 + 0.4 * scale;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
